﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCDto.OA.WorkflowTemplate.WorkflowCategory;
using BCService.OA.WorkflowTemplate.WorkflowCategory;
using BCTMSRESTful.Configs;
using System.Net;
using BCCommon;
using BCService.Utils;

namespace BCTMSRESTful.Controllers.Management.OA.WorkflowTemplate
{
    /// <summary>
    /// 工作流操作
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class WorkflowCategoryController : ManagementBaseController
    {
        private readonly IWorkflowCategoryService workflowCategoryService;

        public WorkflowCategoryController(IWorkflowCategoryService workflowCategoryService)
        {
            this.workflowCategoryService = workflowCategoryService;
        }

        /// <summary>
        /// 添加工作流分类
        /// </summary>
        /// <param name="requestDto">工作流分类信息</param>
        /// <response code="201">添加工作流分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加工作流分类")]
        [ProducesResponseType(typeof(WorkflowCategoryDto), 201)]
        public IActionResult Post([FromBody]WorkflowCategoryRequestDto requestDto)
        {
            var result = this.workflowCategoryService.Add(requestDto,this.Admin);
            return StatusCode((int)HttpStatusCode.Created, result);
        }

        #region 修改工作流分类
        /// <summary>
        ///  修改工作流分类
        /// </summary>
        /// <param name="workflowCategoryId">工作流分类Id</param>
        /// <param name="requestDto">工作流分类信息</param>
        /// <response code="200">修改工作流分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{workflow_category_id}")]
        [Log("修改工作流分类")]
        [ProducesResponseType(typeof(WorkflowCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "workflow_category_id")] long workflowCategoryId, [FromBody] WorkflowCategoryRequestDto requestDto)
        {
            WorkflowCategoryPutDto putDto = requestDto.As<WorkflowCategoryPutDto>();
            putDto.WorkflowCategoryId = workflowCategoryId;
            return StatusCode((int)HttpStatusCode.OK, this.workflowCategoryService.Update(putDto,this.Admin));
        }
        #endregion

        #region 删除工作流分类
        /// <summary>
        ///  删除工作流分类
        /// </summary>
        /// <param name="workflowCategoryId">工作流分类Id</param>
        /// <response code="204">删除工作流分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{workflow_category_id}")]
        [Log("删除工作流分类")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "workflow_category_id")] long workflowCategoryId)
        {
            this.workflowCategoryService.Delete(workflowCategoryId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取工作流分类
        /// <summary>
        ///  获取工作流分类
        /// </summary>
        /// <param name="workflowCategoryId">工作流分类Id</param>
        /// <response code="200">获取工作流分类</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{workflow_category_id}")]
        [ProducesResponseType(typeof(WorkflowCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "workflow_category_id")] long workflowCategoryId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowCategoryService.Get(workflowCategoryId));
        }
        #endregion

        #region 获取工作流分类列表
        /// <summary>
        ///  获取工作流分类列表
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <response code="200">获取工作流分类列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(WorkflowCategoryDto), 200)]
        public IActionResult List([FromQuery(Name = "company_id")]int? companyId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowCategoryService.GetList(companyId));
        }
        #endregion

        #region 获取工作流分类（分页）
        /// <summary>
        ///  获取工作流分类（分页）
        /// </summary>
        /// <param name="companyId">公司Id</param>
        /// <param name="categoryName">分类名称</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">当前页大小</param>
        /// <response code="200">获取工作流分类（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WorkflowCategoryDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "conpamy_id")] int? companyId,
            [FromQuery(Name = "category_name")] string categoryName,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.workflowCategoryService.Query(companyId, categoryName,start, end, sortName, ascending, pageIndex, pageSize));
        }
        #endregion  
    }
}
